from django import forms
from django.forms import widgets
from .models import CustomUser
from django.core import validators
from .validators import MyLength


class LoginForm(forms.Form):
    username = forms.CharField(label="用户名", widget=widgets.TextInput(attrs={
        "id": "username",
        "class": "form-control",
        "placeholder": "请输入用户名"
    }), validators=(validators.MaxLengthValidator(10),),)
    password = forms.CharField(label="密码", widget=widgets.PasswordInput(attrs={
        "id": "password",
        "class": "form-control",
        "placeholder": "请输入密码"
    }), validators=(MyLength(10),),)


class RegistForm(forms.ModelForm):
    password2 = forms.CharField(label="确认密码", widget=widgets.PasswordInput(attrs={
        "id": "password2",
        "class": "form-control",
        "placeholder": "请再次输入密码"
    }))

    class Meta:
        model = CustomUser
        fields = ["username", "password", "email", "telephone"]
        labels = {
            "username": "用户名"
        }
        widgets = {
            "username": widgets.TextInput(attrs={
                "id": "username",
                "class": "form-control",
                "placeholder": "请输入用户名"
            }),
            "password": widgets.PasswordInput(attrs={
                "id": "password",
                "class": "form-control",
                "placeholder": "请输入密码"
            }),
            "email": widgets.EmailInput(attrs={
                "id": "email",
                "class": "form-control",
                "placeholder": "请输入邮箱"
            }),
            "telephone": widgets.TextInput(attrs={
                "id": "telephone",
                "class": "form-control",
                "placeholder": "请输入手机号"
            })

        }
        help_texts = {
            "username": "你是一个一个一个"
        }


class CenterForm(forms.ModelForm):
    class Meta:
        model = CustomUser
        fields = ["username", "email", "telephone", "first_name", "last_name", "head"]
        widgets = {
            "username": widgets.TextInput(attrs={
                "id": "username",
                "class": "form-control",
                "placeholder": "请输入用户名"
            }),
            "email": widgets.TextInput(attrs={
                "id": "email",
                "class": "form-control",
                "placeholder": "请输入邮箱"
            }),
            "telephone": widgets.TextInput(attrs={
                "id": "telephone",
                "class": "form-control",
                "placeholder": "请输入手机号"
            }),
            "first_name": widgets.TextInput(attrs={
                "id": "first_name",
                "class": "form-control",
                "placeholder": "请输入名字"
            }),
            "last_name": widgets.TextInput(attrs={
                "id": "last_name",
                "class": "form-control",
                "placeholder": "请输入姓氏"
            }),
        }


class UpdatePasswordForm(forms.Form):
    password0 = forms.CharField(label="原密码", widget=widgets.PasswordInput(attrs={
        "id": "password0",
        "class": "form-control",
        "placeholder": "请输入原始密码"
    }))
    password1 = forms.CharField(label="新密码", widget=widgets.PasswordInput(attrs={
        "id": "password1",
        "class": "form-control",
        "placeholder": "请输入新密码"
    }))
    password2 = forms.CharField(label="确认新密码", widget=widgets.PasswordInput(attrs={
        "id": "password2",
        "class": "form-control",
        "placeholder": "请再次输入新密码"
    }))